﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Services_ServiceGuest : System.Web.UI.Page
{ 
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        lblPath.Text = f.getModuleidAdd(Request.QueryString["moduid"].ToString());
        if (!IsPostBack)
        {
            hfxs.Value = Request.QueryString["moduid"].ToString();
            TypeName.Text = Request.QueryString["TypeName"];
            ComodBarcode.Text = Request.QueryString["ComodBarcode"];
            catalogueName.Text = Request.QueryString["catalogueName"];
            StockNum.SelectedValue = Request.QueryString["StockNum"];
            initData();
        }
    }


    private void initData()
    {
        string search = "";
        string sql = "SELECT catalogueId, ComodBarcode, catalogueName, Units, Spec,Prices,ProcMoney, Remark, AuditState, EditUserName,Convert(char(10),EditDate,120) as EditDate ,(SELECT TypeName  FROM SV_Type  WHERE a.TypeId = TypeId) AS TypeName,(SELECT Units FROM Units where a.Units=UnitsId) as UnitsName ,(select isnull(sum(ProcNum),0) from SV_Stock where ComodBarcode=a.ComodBarcode) as StockNum FROM SV_Catalogue a where 1=1 ";

        if (!string.IsNullOrEmpty(Request.QueryString["ComodBarcode"]))//订单号
        {
            search += "&ComodBarcode=" + Request.QueryString["ComodBarcode"].Trim();
            sql += " and ComodBarcode like '%" + Request.QueryString["ComodBarcode"].Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["catalogueName"]))//客户名称
        {
            search += "&catalogueName=" + Request.QueryString["catalogueName"].Trim();
            sql += " and catalogueName like '%" + Request.QueryString["catalogueName"].Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["TypeName"]))//商品名称
        {
            search += "&TypeName=" + Request.QueryString["TypeName"].Trim();
            sql += " and TypeName like '%" + Request.QueryString["TypeName"].Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["StockNum"]))
        {
            search += "&StockNum=" + Request.QueryString["StockNum"];
            sql += "  and StockNum" + Request.QueryString["StockNum"];
        }
        sql += " order by catalogueId desc";
        PageNavigator1.Url = "../Services/selectCatalogue.aspx?moduid=" + hfxs.Value + search;
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;


    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = "";
        if (!string.IsNullOrEmpty(ComodBarcode.Text.Trim()))//订单号
        {
            search += "&ComodBarcode=" + Common.FormatParameter(ComodBarcode.Text.Trim());
        }
        if (!string.IsNullOrEmpty(catalogueName.Text.Trim()))//客户名称
        {
            search += "&catalogueName=" + Common.FormatParameter(catalogueName.Text).Trim();
        }
        if (!string.IsNullOrEmpty(TypeName.Text.Trim()))//商品名称
        {
            search += "&TypeName=" + Common.FormatParameter(TypeName.Text).Trim();
        }
        if (!string.IsNullOrEmpty(StockNum.Text))//库存
        {
            search += "&StockNum=" + Common.FormatParameter(StockNum.Text);
        }
        PageNavigator1.Url = "../Services/selectCatalogue.aspx?moduid=" + hfxs.Value + search;
        Response.Redirect("selectCatalogue.aspx?moduid=" + hfxs.Value + search);
    }


    protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)//在邦定数据
    {
        //f.checkLevels(Request.Cookies["user"].Values["roleid"], hfxs.Value, 4, GvDataType, btndel, btnallflag, btnAdd);//权限string lyyybz = "";
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           // string StrReturn = "";
            string StrReturn = DataBinder.Eval(e.Row.DataItem, "TypeName").ToString() + "||" + DataBinder.Eval(e.Row.DataItem, "catalogueName").ToString() + "||" + DataBinder.Eval(e.Row.DataItem, "ComodBarcode").ToString() + "||" + DataBinder.Eval(e.Row.DataItem, "Spec").ToString() + "||" + DataBinder.Eval(e.Row.DataItem, "UnitsName").ToString() + "||" + DataBinder.Eval(e.Row.DataItem, "Prices").ToString() + "||" + DataBinder.Eval(e.Row.DataItem, "ProcMoney").ToString();
            e.Row.Attributes.Add("ondblclick", "selectInfo('" + StrReturn + "')");
            //e.Row.Cells[11].Attributes.Add("onmouseout", "Remove()");

        }    
        
    }


}
